<!--
  -    Copyright (c) 2018-2025, seefa All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without
  - modification, are permitted provided that the following conditions are met:
  -
  - Redistributions of source code must retain the above copyright notice,
  - this list of conditions and the following disclaimer.
  - Redistributions in binary form must reproduce the above copyright
  - notice, this list of conditions and the following disclaimer in the
  - documentation and/or other materials provided with the distribution.
  - Neither the name of the pig4cloud.com developer nor the names of its
  - contributors may be used to endorse or promote products derived from
  - this software without specific prior written permission.
  - Author: seefa
  -->

<template>
  <div class="execution">
    <el-form
      :inline="true"
      :model="formInline"
      class="demo-form-inline"
      style="padding: 1.5rem 0 0 1rem;
    background: #ffff;
    margin: 0 0.7rem;"
    >
      <el-form-item label="订单编号">
        <el-input v-model="formInline.orderNo" placeholder="订单编号"></el-input>
      </el-form-item>
      <el-form-item label="预审编号">
        <el-input v-model="formInline.pretrialNum" placeholder="预审编号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>

    <basic-container>
      <avue-crud
        ref="crud"
        :page="page"
        :data="tableData"
        :table-loading="tableLoading"
        :option="tableOption"
        @row-update="handleUpdate"
        @row-save="handleSave"
        @search-change="searchChange"
        @size-change="sizeChange"
        @current-change="currentChange"
        @row-del="rowDel"
      >
        <template slot="menu" slot-scope="scope">
          <el-button
            size="small"
            type="text"
            v-if="scope.row.isSuccess==1"
            style="color:#ccc;"
          >发送</el-button>
          <el-button
            @click="sendMessage(scope.row,scope.index)"
            size="small"
            type="text"
            v-else
          >发送</el-button>

        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import {
  sendObj,
  fetchList,
} from "@/api/maintenance/index";
import { tableOption } from "@/const/crud/maintenance/index";

export default {
  name: "maintenance",
  data() {
    return {
      searchForm: {},
      form: {},
      formInline: {
        orderNo: "",
        pretrialNum: ""
      },
      tableData: [],
      tableDictItemData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 20 // 每页显示多少条
      },
      tableLoading: false,
      tableOption: tableOption
    };
  },

  methods: {
    sendMessage(item) {
              this.$confirm('是否确认发送?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function () {
          sendObj({
            assetOrderNo:item.assetOrderNo,
            taskFlag:item.taskFlag,
            uid:item.uid
          })
        }).then(() => {
          this.getList(this.page);
          this.$message.success("发送成功,请1分钟后再次查看订单状态");
        }).catch(function () {
        })
      console.log(item)
    },
    onSubmit() {
      if (this.formInline.orderNo == "") {
        this.$message.error("请输入订单编号");
        return false;
      }
      this.getList(this.page);
    },
    getList(page, params) {
      this.tableLoading = true;
      fetchList(
        Object.assign(
          {
            pageNum: page.currentPage,
            pageSize: page.pageSize,
            assetOrderNo: this.formInline.orderNo,
            pretrialNum: this.formInline.pretrialNum
          },
          params,
          this.searchForm
        )
      ).then(response => {
        this.tableData = response.data.data.list;
        this.page.total = response.data.data.total;
        this.tableLoading = false;
      });
    },
    rowDel: function(row) {
      this.$confirm(
        '是否确认删除数据类型为"' + row.type + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(function() {
          return delObj(row);
        })
        .then(() => {
          this.getList(this.page);
          this.$message.success("删除成功");
        })
        .catch(function() {});
    },
    handleUpdate: function(row, index, done) {
      putObj(row).then(() => {
        this.$message.success("修改成功");
        this.getList(this.page);
        done();
      });
    },
    handleSave: function(row, done) {
      addObj(row).then(() => {
        this.$message.success("添加成功");
        this.getList(this.page);
        done();
      });
    },
    searchChange(form, done) {
      this.searchForm = form;
      this.getList(this.page, form);
      done();
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    currentChange(current) {
      this.page.currentPage = current;
    },
    //======字典项表格相关=====
    dictItemVisible: function() {
      this.dialogFormVisible = false;
      this.itemPage.currentPage = 1;
    },
    handleItem: function(row) {
      this.getDictItemList(row.id, row.type);
    },
    getDictItemList(dictId, type) {
      this.dictType = type;
      this.dictId = dictId;
      this.dialogFormVisible = true;
      fetchItemList(
        Object.assign(
          {
            current: this.itemPage.currentPage,
            size: this.itemPage.pageSize
          },
          { dictId: dictId }
        )
      ).then(response => {
        this.tableDictItemData = response.data.data.records;
        this.itemPage.total = response.data.data.total;
      });
    },
    handleBeforeOpen(done) {
      this.form.type = this.dictType;
      this.form.dictId = this.dictId;
      done();
    },
    handleItemSave: function(row, done) {
      addItemObj(row).then(() => {
        this.$message.success("添加成功");
        this.getDictItemList(row.dictId, row.type);
        done();
      });
    },
    handleItemUpdate: function(row, index, done) {
      putItemObj(row).then(() => {
        this.$message.success("修改成功");
        this.getDictItemList(row.dictId, row.type);
        done();
      });
    },
    itemSizeChange(pageSize) {
      this.itemPage.pageSize = pageSize;
      this.getDictItemList(this.dictId, this.type);
    },
    itemCurrentChange(current) {
      this.itemPage.currentPage = current;
      this.getDictItemList(this.dictId, this.type);
    },
    rowItemDel: function(row) {
      this.$confirm('是否确认删除数据为"' + row.label + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          return delItemObj(row.id);
        })
        .then(() => {
          this.getDictItemList(row.dictId, row.type);
          this.$message.success("删除成功");
        })
        .catch(function() {});
    }
  }
};
</script>

<style lang="scss" scoped>
</style>

